package com.xin.di.uav.applet.mapper;

import com.xin.di.uav.applet.po.UserAccountPO;
import com.xin.di.uav.operate.po.ServiceAreaPO;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface UserAccountMapper {


    @Select({"<script>",
            "select count(1) \n" +
                    "from user_accounts WHERE 1=1 ",
            "    <if test='phone != null and phone !=\"\" '> AND phone_number = #{phone}</if>",
            "<if test='startTime != null '>" +
                    " AND create_time &gt; #{startTime} AND create_time &lt; #{endTime} </if>",
            "</script>"})
    int count(@Param("phone") String phone, @Param("startTime") Date startTime, @Param("endTime") Date endTime);


    @Select({"<script>",
            "select id, phone_number, display_name,  user_name, status, creator, create_time, updater,\n" +
                    "                           update_time, password \n" +
                    " from user_accounts WHERE 1=1 " +
                    "    <if test='phone != null and phone !=\"\" '> AND phone_number = #{phone}</if>",
            "<if test='startTime != null '>" +
                    " AND create_time &gt; #{startTime} AND create_time &lt; #{endTime} </if>",
            " order by create_time desc   limit #{offset},#{pageSize} ",
            "</script>"})
    List<UserAccountPO> selectList(@Param("offset") int offset, @Param("pageSize") int pageSize, @Param("phone") String phone
            , @Param("startTime") Date startTime, @Param("endTime") Date endTime);


    @Insert({"<script>",
            "insert into user_accounts (id, phone_number, display_name, user_name, status, creator,creator_id, updater, password)\n" +
                    "values (#{id}, #{phoneNumber}, #{displayName}, #{userName}, #{status}, #{creator},#{creatorId}, #{updater}, #{password})",
            "</script>"})
    int insert(UserAccountPO userAccountPO);


    @Select({"<script>",
            "select id, phone_number, display_name, user_name, status, creator, creator_id, create_time, updater,\n" +
                    "                           update_time, password \n" +
                    " from user_accounts WHERE id=#{id} " +
                    "</script>"})
    UserAccountPO selectById(@Param("id") String id);


    @Update({
            "<script>",
            "UPDATE user_account ",
            "<set>",
            "    <if test='displayName != null'>display_name = #{displayName},</if>",
            "    updated_at = NOW()",

            "</set>",
            "WHERE id = #{id}",
            "</script>"
    })
    int updateById(UserAccountPO userAccountPO);

}
